import {request} from "../../utils/util";

let app = getApp()
Page({
  data: {
    bannerData: [],
    swiperIdx: 0,
    top: app.globalData.rightBarInfo.top,
    height: app.globalData.rightBarInfo.height,
    menu: []
  },
  nav (ev) {
    let { item } = ev.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/classify/index?venue_id=${item.id}`
    })
  },
  // 轮播特效果二
  bindChange(e) {
    console.log(e)
    this.setData({
      swiperIdx: e.detail.current
    })
  },
  // 获取banner数据
  getBanner() {
    request({
      url: '/api/web/slideshow',
      success: ({ code, data }) => {
        if (code === 200) {
          this.setData({
            bannerData: data
          })
        }
      }
    })
  },
  // 获取列表数据
  getList() {
    wx.showLoading({
      title: '加载中..',
      mask: true
    })
    request({
      url: '/api/web/shop/index',
      success: ({ code, data, message }) => {
        wx.hideLoading()
        if (code === 200) {
          this.setData({
            menu: data
          })
        } else {
          wx.showToast({
            title: message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  onClickBanner(ev) {
    let { item } = ev.currentTarget.dataset;
    if (item.link) {
      wx.navigateTo({
        url: `/${item.link.replace('.html', '')}`
      })
    }
  },
  onLoad () {
    console.log(app.globalData)
    this.getBanner();
    this.getList();
  },
})
